package com.source.zookeeper;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.ACL;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ZookTest {
   ZooKeeper zooKeeper;
   CountDownLatch  countDownLatch =new CountDownLatch(1);

   /* @Before
    public void testBefore() throws Exception {
        zooKeeper=new ZooKeeper("192.168.234.131:2181", 5000, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                System.out.println();
                if(watchedEvent.getState().getIntValue()==0){
                    countDownLatch.countDown();
                }
            }
        });
        countDownLatch.await();
        TimeUnit.SECONDS.sleep(2);
    }

    @After
    public void testAfter() throws InterruptedException {
       zooKeeper.close();
    }*/


    public void testMain() throws Exception {
        List<ACL> aclList=new ArrayList<ACL>();
        ACL acl1 = new ACL();

     ZooKeeper   zooKeeper=new ZooKeeper("192.168.234.131:2181", 5000,null);

     //   countDownLatch.await();
        TimeUnit.SECONDS.sleep(1);
        String s = zooKeeper.create("/redis", "weng1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        System.out.println("......................");
        System.out.println(s);
        System.out.println(zooKeeper.getSessionId());
        System.out.println("......................");
    }





    }

